package com.cnpinxi.service;

import com.cnpinxi.dao.MessageBoardMapper;
import com.cnpinxi.domain.MessageBoard;
import com.cnpinxi.myRunTime.MyRunTimeExcption;
import com.cnpinxi.service.*;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * Created by Baggio on 2017-11-21.
 */
@Service
public class MessageBoardServiceImpl implements com.cnpinxi.service.MessageBoardService {
    @Autowired
    MessageBoardMapper messageBoardMapper;
    @Override
    public void insertMessageBoard(MessageBoard record) {
        messageBoardMapper.insertMessageBoard(record);
    }

    @Override
    public List<MessageBoard> getMessageBoardList(Map<String, String> map) {
        return messageBoardMapper.getMessageBoardList(map);
    }

    @Override
    public MessageBoard getMessageBoard(Map<String, String> map) {
        return messageBoardMapper.getMessageBoard(map);}

    @Override
    public void updateMessageBoardById(MessageBoard record) {
        messageBoardMapper.updateMessageBoardById(record);
    }

    @Override
    public void modifyMessageBoardStatus(Long tid, Byte status) {
        Map<String,String> map=new HashMap<>();
        map.put("tid",String.valueOf(tid));
        MessageBoard messageBoard=messageBoardMapper.getMessageBoard(map);
        if(messageBoard==null){
            throw new MyRunTimeExcption("留言没有找到！");
        }
        messageBoard.setStatus(status);
        this.updateMessageBoardById(messageBoard);
    }
}
